import requestNovelsLib
if __name__ == '__main__':
    argvDict = requestNovelsLib.initParamArgs()
    readKeyWordFiles = argvDict.get("s")
    if readKeyWordFiles is None or len(readKeyWordFiles) == 0:
        print("找不到需要删除的关键字配置文件")
        exit(-1)
    readRemoveKeyWordFiles = argvDict.get("d")
    if readKeyWordFiles is None or len(readKeyWordFiles) == 0:
        print("找不到需被删除的关键字配置文件")
        exit(-1)
        
        
    compileKeyWord : list[str] = argvDict.get("k")
    if compileKeyWord is None:
        compileKeyWord: list[str] = []
    for sourceReadFile in readKeyWordFiles:
        readConents = requestNovelsLib.readFile(sourceReadFile)
        strip = readConents.split("\n")
        for keyWork in strip:
            compileKeyWord.append(keyWork)
    if len(compileKeyWord) == 0:
        print("找不到需要删除的关键字")
        exec (0)
   
    writeArray:list[str] = []
    for sourceReadFile in readRemoveKeyWordFiles:
        readConents = requestNovelsLib.readFile(sourceReadFile)
        strip = readConents.split("\n")
        for keyWork in strip:
            if compileKeyWord.count(keyWork) == 0:
                writeArray.append(keyWork)
    writeFile  = argvDict.get("o")
    if writeFile is None or len(writeFile) == 0:
        writeFile = readRemoveKeyWordFiles[0]
    else:
        writeFile = writeFile[0]
    contents = "\n".join(writeArray)+"\n"
    requestNovelsLib.writeFile(contents, writeFile)
    
    
    